#!/bin/sh

ARCH=`uname -m`
if [ "$ARCH" != "x86_64" ]; then
    ARCH="x86"
fi

#  This function is to find the dist name and update which the kernel belongs to. 
#  global variables needed, which are defined in ${ROOT}/.config
#      DISTS, DIST_UPDATES_<dist>, KERENL_<dist>_<update>_COMMON, KERNEL_<dist>_<update>_<arch>
#  outputs are also in gloable variables
#      DIST, UPDATE
find_dist_update()
{
	# find the DIST, UPDATE
	for dist in $DISTS
	do
		eval updates=\$DIST_UPDATES_$dist
		for update in $updates
		do
			eval common_kernels=\$KERNEL_${dist}_${update}_COMMON
			eval arch_kernels=\$KERNEL_${dist}_${update}_$ARCH
			kernels="$common_kernels $arch_kernels"
			echo $kernels | tr ' ' '\n' | grep -q "^${KERNEL}$"
			if [ $? -eq 0 ]; then
				UPDATE=$update
				DIST=$dist
				break 2
			fi
		done
	done
}
